package com.ifacebox.web.admin.master.dao;

import com.ifacebox.web.admin.master.model.MasterNotice;
import com.ifacebox.web.admin.master.model.MasterUser;
import com.ifacebox.web.admin.master.model.MasterUserNotice;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author znn
 */
@Mapper
@Component
public interface MasterUserNoticeDao {

    @Select({"<script>"
            , "SELECT * FROM master_user_notice WHERE user_id = #{userId} AND notice_id = #{noticeId}"
            , "</script>"})
    List<MasterUserNotice> query(MasterUserNotice masterUserNotice);

    @Select({"<script>"
            , "SELECT master_user.* FROM master_user,master_user_notice"
            , "WHERE master_user.id = master_user_notice.user_id AND master_user_notice.notice_id = #{noticeId}"
            , "</script>"})
    List<MasterUser> queryReadMasterUserByNoticeId(Integer noticeId);

    @Insert({"<script>"
            , "INSERT INTO master_user_notice"
            , "( user_id, notice_id ) VALUES ( #{userId}, #{noticeId} )"
            , "</script>"})
    Integer save(MasterUserNotice masterUserNotice);

    @Delete({"<script>"
            , "DELETE FROM master_user_notice WHERE user_id = #{userId}"
            , "</script>"})
    Integer deleteByUserId(Integer userId);

    @Delete({"<script>"
            , "DELETE FROM master_user_notice WHERE notice_id = #{noticeId}"
            , "</script>"})
    Integer deleteByNoticeId(Integer noticeId);
}
